# -*- coding:utf-8 -*-

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from AutoTestBDC.WorkFlow.User import User
from AutoTestBDC.extScript.GetList import GetListValue
from AutoTestBDC.extScript.SeaValue import SeaValue
from time import sleep

class CS(User):
    def __init__(self,driver,username,userpwd,type=None,caseno=None,qlrtype=None):
        super().Login(driver,username, userpwd)
        self.driver = driver
        self.type = type
        self.caseno = caseno
        self.qlrtype = qlrtype

        driver.find_element_by_css_selector(u"img[title=\"待审核\"]").click()
        SeaValue(driver, caseno, qlrtype)

        glv = GetListValue()
        if qlrtype == "自然人":
            tablexpath = "/html/body/content/div/form/div/div[19]"

        if qlrtype == "法人机构":
            tablexpath = "/html/body/content/div/form/div/div[20]"

        if qlrtype == "其他组织":
            tablexpath = "/html/body/content/div/form/div/div[21]"
        glv.clickvalue(driver, tablexpath, caseno)

        self.test_tester()

    def test_tester(self):
        if self.type == "通过":
            self.set_pass()

        if self.type == "不通过":
            self.set_fail()

        if self.type == "退回前台":
            self.set_backtogt()

        super().Logout()

    def set_pass(self):
        self.driver.execute_script("arguments[0].scrollIntoView();", self.driver.find_element_by_id("detail-pass"))
        self.driver.find_element_by_id("detail-pass").click()

        sleep(1)
        #self.driver.find_element_by_id("detail-pass").click()
        self.driver.find_element_by_id("uid").click()
        self.driver.find_element_by_css_selector("button.modal_confirm").click()

    def set_fail(self):
        self.driver.find_element_by_xpath("/html/body/content/div/div[3]/div[4]/input").click()

        self.driver.find_element_by_css_selector("div.nowrap > div.check > input[name=\"ifpass[]\"]").click()
        self.driver.find_element_by_id("reasonbzCS").clear()
        self.driver.find_element_by_id("reasonbzCS").send_keys("不通过")
        sleep(1)
        self.driver.find_element_by_css_selector("button.fail_submit_single").click()
        sleep(1)

        self.driver.execute_script("arguments[0].scrollIntoView();", self.driver.find_element_by_id("detail-fail"))
        self.driver.find_element_by_id("detail-fail").click()
        sleep(1)
        self.driver.find_element_by_css_selector("button.fail_submit").click()

    def set_backtogt(self):
        self.driver.execute_script("arguments[0].scrollIntoView();",
                                   self.driver.find_element_by_id("detail-return"))
        self.driver.find_element_by_id("detail-return").click()
        sleep(1)
        self.driver.find_element_by_css_selector("div.modal_container.modal_return > button.modal_confirm").click()
